import * as cc from 'cc';
import * as ecs from '@esengine/ecs-framework';
import { ESCWorld } from '../ESCWorld';
import { LocalTransform } from '../component/LocalTransform';
import { RenderComponent } from '../component/SpriteComponent';

const { ccclass, property } = cc._decorator;

@ccclass('ECSNode')
export class ECSNode extends cc.Component {
    entity: ecs.Entity;

    protected onLoad(): void {
        this.entity = ESCWorld.instance
            .getEntityManager()
            .createEntity('Player');
        this.entity.addComponent(
            new LocalTransform(
                { x: this.node.position.x, y: this.node.position.y },
                { x: this.node.scale.x, y: this.node.scale.y },
                0,
            ),
        );

        this.entity.addComponent(new RenderComponent(this.node));

        this.entity.active = true;
        this.entity.tag = 1;
        ESCWorld.instance.getScene().addEntity(this.entity);

    }
    start() {}

    update(deltaTime: number) {}
}
